package cn.stylefeng.guns.modular.resultScore.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.question.param.questionParam;
import cn.stylefeng.guns.modular.resultScore.entity.Echarts;
import cn.stylefeng.guns.modular.resultScore.entity.resultScoreEntity;
import cn.stylefeng.guns.modular.resultScore.param.resultScoreParam;
import cn.stylefeng.guns.modular.resultScore.service.resultScoreService;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class resultScoreController {

    @Resource
    private resultScoreService resultScoreService;

    @GetMapping("/result/list")
    @BusinessLog(title = "quenstion_org_增加_查询单位", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData selectUnit(resultScoreParam resultScoreParam){
        List<resultScoreEntity> list = resultScoreService.selectUnitService(resultScoreParam.getTid());
        return new SuccessResponseData(list);
    }

    @PostMapping("/result/add")
    @BusinessLog(title = "quenstion_org_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(resultScoreParam.add.class) resultScoreParam resultScoreParam) {
        resultScoreService.add(resultScoreParam);
        return new SuccessResponseData();
    }

    @PostMapping("/result/delete")
    @BusinessLog(title = "quenstion_org_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(resultScoreParam.delete.class) resultScoreParam resultScoreParam) {
        resultScoreService.delete(resultScoreParam);
        return new SuccessResponseData();
    }

    @PostMapping("/result/edit")
    @BusinessLog(title = "quenstion_org_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(resultScoreParam.edit.class) resultScoreParam resultScoreParam) {
        resultScoreService.edit(resultScoreParam);
        return new SuccessResponseData();
    }

    @GetMapping("/result/echarts")
    public ResponseData EchartsView(questionParam questionParam){
        Map<String,Integer> map = new HashMap<>();
        map.put("60分以下",resultScoreService.selectAvgNumsService(0,60));
        map.put("60-80分",resultScoreService.selectAvgNumsService(60,80));
        map.put("80-100分",resultScoreService.selectAvgNumsService(80,101));

        return new SuccessResponseData(map);
    }


}
